<template>
  <view class="container">
    <uni-table border stripe>
      <uni-tr>
        <uni-th width="100" align="center">账号</uni-th>
        <uni-th width="100" align="center">姓名</uni-th>
        <uni-th width="150" align="center">手机号</uni-th>
        <uni-th width="150" align="center">添加时间</uni-th>
      </uni-tr>
      <uni-tr v-for="item in dataList" :key="item.guid">
        <uni-td>{{ item.account }}</uni-td>
        <uni-td>{{ item.name }}</uni-td>
        <uni-td>{{ item.mobile }}</uni-td>
        <uni-td>{{ item.addtime }}</uni-td>
      </uni-tr>
    </uni-table>

    <uni-pagination 
      :total="total"
      :current="currentPage"
      :pageSize="pageSize"
      @change="handlePageChange"
    />
  </view>
</template>

<script>
import axios from '../../node_modules/axios';

export default {
  data() {
    return {
      dataList: [],
      total: 0,
      currentPage: 1,
      pageSize: 10
    };
  },
  created() {
    this.getUserList();
  },
  methods: {
    async getUserList() {
      try {
        const res = await axios.post(
          'http://localhost:20300/base/getUserPageList',
          {},
          {
            headers: {
              userGuid: '2BCF0189-C941-4D9D-B16F-44E6298D033E',
              token: '95253392-a4a3-44c3-9228-cead3787940a'
            }
          }
        );
        
        if (res.data.code === '0000') {
          this.dataList = res.data.data.dataList;
          this.total = res.data.data.dataList.length;
        }
      } catch (error) {
        console.error('获取用户列表失败', error);
      }
    },
    handlePageChange(e) {
      this.currentPage = e.current;
      this.getUserList();
    }
  }
};
</script>

<style>
.container {
  padding: 20px;
}
</style>
